package com.ganxiang.ximenhong.model;

import android.os.Handler;
import android.os.Message;

import java.util.ArrayList;

public class MessageManager {
	public static MessageManager manager;
	private ArrayList<Handler> mHandlers = new ArrayList<Handler>();
	public static final int MessageType_Logout = 0, MessageType_Login = 1,
			MessageType_Update_UserInfo = 2,
			MessageType_show_which_fragment = 3,
			MessageType_vertical_auto_tv = 4;

	private MessageManager() {

	}

	public static MessageManager getInstance() {
		if (manager == null) {
			manager = new MessageManager();
		}
		return manager;
	}

	public void addHandler(Handler handler) {
		if (!mHandlers.contains(handler)) {
			mHandlers.add(handler);
		}
	}

	public void removeHandler(Handler handler) {
		mHandlers.remove(handler);
	}

	public void sendMessage(int msgType, Object object) {
		for (Handler handler : mHandlers) {
			Message msg = handler.obtainMessage();
			msg.what = msgType;
			msg.obj = object;
			handler.sendMessage(msg);
		}
	}
}
